﻿using ControllerLayer;
using ControllerLayer.AStar;
using ModelLayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace GraphTUI
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            AStarTest.InitializeAStarGraph();
        }
    }

    internal class AStarTest
    {
        public static void InitializeAStarGraph()
        {
            var stationsCtr = new StationCtr();

            var statList = stationsCtr.GetAllStation();
            var nodeList = new List<Node>();

            foreach (Station station in statList)
            {
                var n = new Node(station);
                n.Edges = stationsCtr.GetStationEdges(station.Id);
                nodeList.Add(n);
            }

            List<Edge> edgeList = stationsCtr.GetAllEdges();
            Graph graph = new Graph(nodeList, edgeList);

            Node startNode = (from n in nodeList where n.Station.Id == 1 select n).FirstOrDefault();
            Node endNode = (from n in nodeList where n.Station.Id == 22 select n).FirstOrDefault();
            if (startNode != null && endNode != null)
            {
                Console.WriteLine("\rFra station: " + startNode.Station.Name);
                Console.WriteLine("\rTil station: " + endNode.Station.Name);

                startNode.Edges = stationsCtr.GetStationEdges(startNode.Station.Id);

                IEnumerable<PartRoute> partRoutes = graph.MinDistancePath(startNode.Station, endNode.Station);
                Console.WriteLine("Genererated route using AStar");

                foreach (PartRoute pRoute in partRoutes)
                {
                    Console.WriteLine("I traveled from " + pRoute.LocationStart.Name + " to " + pRoute.LocationEnd.Name +
                                      ", this was " + pRoute.Distance + "km");
                }
            }

            Console.ReadLine();
        }
    }
}